﻿<template>
    <div id="app">
        <mt-header v-bind:title="title" style="background-color:#fda10e">
            <a slot="left" @click="back()">返回</a>

        </mt-header>

        <ul class="mui-table-view mui-grid-view">
            <li class="mui-table-view-cell mui-media mui-col-xs-6" v-for="item in list" @click="go(item)" style="">
                <a >
                    
                    <div :style="{backgroundImage:`url(${item.imgurl})`}" style="height:200px;background-size:cover;border-top-left-radius:1em;border-top-right-radius:1em;background-repeat:no-repeat;">
                      
                    </div>
                    <div>
                        <div style="font-size:14px;width:48%;float:left;text-align:left;font-family:黑体;font-weight:400;">
                            {{item.title|ellipsis4}}
                        </div>
                        <div style="font-size:13px;width:48%;float:left;text-align:right;">
                            {{item.createtime}}
                        </div>


                    </div>
                    <div class="mui-media-body" style="text-align:left;font-size:12px;"> {{item.desc|ellipsis18}}</div>
                </a>
            </li>

        </ul>




        <ul v-infinite-scroll="loadMore"
            infinite-scroll-disabled="busy"
            infinite-scroll-distance="10" class="clearfix">
            <div class="loading">{{loading}}</div>
        </ul>


    </div>

</template>

<script>

    import Bus from '../bus.js'
   
    export default {
        name: 'app',
        data() {
            return {
                title: '风采',
                page: 1,
                list: [],
                busy: true,
                loading: "加载中..."
            }
        },
        filters: {
            ellipsis4(value) {
                if (!value) return ''
                if (value.length > 5) {
                    return value.slice(0, 5) + '...'
                }
                return value
            },
            ellipsis18(value) {
                if (!value) return ''
                if (value.length > 18) {
                    return value.slice(0, 18) + '...'
                }
                return value
            }
        },
        components: {

        },
        mounted() {

            window.history.pushState('forward', null, '#');
            window.history.forward(1);
            window.onpopstate = () => {
                Bus.$emit('val', "show");
                this.$router.go(-1);
            }
        },
        methods:
        {
            go: function (e) {
                Bus.$emit('val', "hide")
                this.$router.push({ name: 'newspage', params: { id: e.id } });

            },
            loadMore() {

                this.$data.busy = true  //将无限滚动给禁用
                setTimeout(() => {  //发送请求有时间间隔第一个滚动时间结束后才发送第二个请求
                    this.$data.page = this.$data.page + 1;
                    this.load();
                }, 500);




            },
            load: function () {
                var mid = window.localStorage.getItem("mid");
                var page = this.$data.page;
                var _this = this;
                this.$api.post('wx/Index/getnews', {
                    "mid": mid, "page": page
                }, response => {
                    if (response.status >= 200 && response.status < 300) {
                        console.log(response.data);
                        var data = response.data;
                        if (data.status == 200) {

                            if (data.data.length > 0) {
                                for (var i = 0; i < data.data.length; i++) {

                                    _this.$data.list.push(data.data[i]);
                                }


                                _this.$data.busy = false;
                            } else {

                                _this.$data.busy = true;
                                _this.$data.loading = "没有数据了";
                            }

                        }


                        console.log(_this.$data.list);

                        //请求成功，response为成功信息参数
                    } else {
                        console.log(response.message);
                        //请求失败，response为失败信息
                    }
                });

            },
            back: function () {
                Bus.$emit('val', "show")
                this.$router.go(-1);
            }
        },
        created: function () {
            this.load();
            Bus.$emit('backshow', 1);
        }

    }
</script>

<style scoped>
    @import "../assets/css/mui.min.css";

    .loading {
        width: 100%;
        margin-bottom: 2px;
        text-align: center;
    }
</style>